home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / DefaultTableModel.java < prev    next >
Text File  |  1998-06-30  |  24KB  |  654 lines

  1. /*
  2.  * @(#)DefaultTableModel.java    1.18 98/04/08
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.table;
  22.  
  23. import java.io.Serializable;
  24. import java.util.Vector;
  25. import java.util.Enumeration;
  26. import com.sun.java.swing.event.TableModelEvent;
  27.  
  28.  
  29. /**
  30.  * This is an implementation of TableModel that uses a Vector of Vectors
  31.  * to store the cell value objects.
  32.  * <p>
  33.  * <b>Note:</b><br>
  34.  * The DefaultTableModel's API contains the methods addColumn(),
  35.  * removeColumn(), but not methods to insert a column at an index
  36.  * nor methods to move the columns.  This is because JTable does
  37.  * not display the columns based on the order of the columns in
  38.  * this model.  So rearranging them here doesn't do much.  See
  39.  * the column ordering methods in TableColumnModel.
  40.  * <p>
  41.  * Warning: serialized objects of this class will not be compatible with
  42.  * future swing releases.  The current serialization support is appropriate
  43.  * for short term storage or RMI between Swing1.0 applications.  It will
  44.  * not be possible to load serialized Swing1.0 objects with future releases
  45.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  46.  * baseline for the serialized form of Swing objects.
  47.  *
  48.  * @version 1.18 04/08/98
  49.  * @author Alan Chung
  50.  * @author Philip Milne
  51.  *
  52.  * @see TableModel
  53.  * @see #getDataVector()
  54.  */
  55. public class DefaultTableModel extends AbstractTableModel implements Serializable {
  56.  
  57. //
  58. // Instance Variables
  59. //
  60.  
  61.     /** The Vector of Vector of Object values */
  62.     protected Vector    dataVector;
  63.  
  64.     /** The Vector of column identifiers */
  65.     protected Vector    columnIdentifiers;
  66.  
  67. //
  68. // Constructors
  69. //
  70.  
  71.     /**
  72.      *  Constructs a default DefaultTableModel which is a table of
  73.      *  zero columns and zero rows.
  74.      */
  75.     public DefaultTableModel() {
  76.         this((Vector)null, 0);
  77.     }
  78.  
  79.     /**
  80.      *  Constructs a DefaultTableModel with <i>numRows</i> and
  81.      *  <i>numColumns</i> of <b>null</b> object values.
  82.      *
  83.      * @param numRows           The number of rows the table holds
  84.      * @param numColumns        The number of columns the table holds
  85.      *
  86.      * @see #setValueAt()
  87.      */
  88.     public DefaultTableModel(int numRows, int numColumns) {
  89.         Vector names = new Vector(numColumns);
  90.         names.setSize(numColumns);
  91.         setColumnIdentifiers(names);
  92.         dataVector = new Vector();
  93.         setNumRows(numRows);
  94.     }
  95.  
  96.     /**
  97.      *  Constructs a DefaultTableModel with as many columns as there are
  98.      *  elements in <i>columnNames</i> and <i>numRows</i> of <b>null</b>
  99.      *  object values.  Each column's name will be taken from
  100.      *  the <i>columnNames</i> vector.
  101.      *
  102.      * @param columnNames       Vector containing the names of the new columns.
  103.      *                          If this null then the model has no columns
  104.      * @param numRows           The number of rows the table holds
  105.      * @see #setDataVector()
  106.      * @see #setValueAt()
  107.      */
  108.     public DefaultTableModel(Vector columnNames, int numRows) {
  109.         setColumnIdentifiers(columnNames);
  110.         dataVector = new Vector();
  111.         setNumRows(numRows);
  112.     }
  113.  
  114.     /**
  115.      *  Constructs a DefaultTableModel with as many columns as there are
  116.      *  elements in <i>columnNames</i> and <i>numRows</i> of <b>null</b>
  117.      *  object values.  Each column's name will be taken from
  118.      *  the <i>columnNames</i> array.
  119.      *
  120.      * @param columnNames       Array containing the names of the new columns.
  121.      *                          If this null then the model has no columns
  122.      * @param numRows           The number of rows the table holds
  123.      * @see #setDataVector()
  124.      * @see #setValueAt()
  125.      */
  126.     public DefaultTableModel(Object[] columnNames, int numRows) {
  127.         this(convertToVector(columnNames), numRows);
  128.     }
  129.  
  130.     /**
  131.      *  Constructs a DefaultTableModel and initializes the table
  132.      *  by passing <i>data</i> and <i>columnNames</i> to the setDataVector()
  133.      *  method.
  134.      *
  135.      * @param data              The data of the table
  136.      * @param columnNames       Vector containing the names of the new columns.
  137.      * @see #getDataVector()
  138.      * @see #setDataVector()
  139.      */
  140.     public DefaultTableModel(Vector data, Vector columnNames) {
  141.         setDataVector(data, columnNames);
  142.     }
  143.  
  144.     /**
  145.      *  Constructs a DefaultTableModel and initializes the table
  146.      *  by passing <i>data</i> and <i>columnNames</i> to the setDataVector()
  147.      *  method. The first index in the Object[][] is the row index and
  148.      *  the second is the column index.
  149.      *
  150.      * @param data              The data of the table
  151.      * @param columnNames       The names of the columns.
  152.      * @see #getDataVector()
  153.      * @see #setDataVector()
  154.      */
  155.     public DefaultTableModel(Object[][] data, Object[] columnNames) {
  156.         setDataVector(data, columnNames);
  157.     }
  158.  
  159. //
  160. // Querying and Modifying the data structure
  161. //
  162.  
  163.     /**
  164.      *  This returns the Vector of Vectors that contains the table's
  165.      *  data values.  The vectors contained in the outer vector are
  166.      *  each a single row of values.  In other words, to get to the cell
  167.      *  at row 1, column 5 <p>
  168.      *
  169.      *  <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code><p>
  170.      *
  171.      *  You can directly alter the returned Vector.  You can change the cell
  172.      *  values, the number of rows. If you need to alter the number of columns
  173.      *  in the model, you can do so with addColumn(), removeColumn(), or
  174.      *  the setDataVector() methods.  Once you have finished modifying the
  175.      *  dataVector,  you <b>must</b> inform the model of the new data using
  176.      *  one of the notification methods. The notification methods
  177.      *  will generate the appropriate TableModelListener messages to notify
  178.      *  the JTable and any other listeners of this model.
  179.      *
  180.      * @see #newDataAvailable()
  181.      * @see #newRowsAdded()
  182.      * @see #setDataVector()
  183.      */
  184.     public Vector getDataVector() {
  185.         return dataVector;
  186.     }
  187.  
  188.     /**
  189.      *  This replaces the current dataVector instance variable with the
  190.      *  new Vector of rows, <i>newData</i>. <i>columnNames</i> are the names
  191.      *  of the new columns.  The first name in <i>columnNames</i> is
  192.      *  mapped to column 0 in <i>newData</i>. Each row in <i>newData</i>
  193.      *  is adjusted to match the number of columns in <i>columnNames</i>
  194.      *  either by truncating the Vector if it is too long, or adding
  195.      *  null values if it is too short.
  196.      *  <p>
  197.      *
  198.      * @param   newData         The new data vector
  199.      * @param   columnNames     The names of the columns
  200.      * @see #newDataAvailable()
  201.      * @see #getDataVector()
  202.      */
  203.     public void setDataVector(Vector newData, Vector columnNames) {
  204.         if (newData == null)
  205.             throw new IllegalArgumentException("setDataVector() - Null parameter");
  206.  
  207.         // Clear all the previous data.
  208.         dataVector = new Vector(0);
  209.  
  210.         // Install the new column structure, this will fireTableStructureChanged
  211.         setColumnIdentifiers(columnNames);
  212.  
  213.         // Add the new rows.
  214.         dataVector = newData;
  215.  
  216.         // Make all the new rows the right length and generate a notification.
  217.         newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
  218.                              TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
  219.     }
  220.  
  221.     /**
  222.      *  This replaces the value in the dataVector instance variable with the
  223.      *  values in the array <i>newData</i>.  The first index in the Object[][]
  224.      *  array is the row index and the second is the column index.
  225.      *  <i>columnNames</i> are the names of the new columns.
  226.      *
  227.      * @see #setDataVector(Vector, Vector)
  228.      */
  229.     public void setDataVector(Object[][] newData, Object[] columnNames) {
  230.         setDataVector(convertToVector(newData), convertToVector(columnNames));
  231.     }
  232.  
  233.     /**
  234.      *  Equivalent to fireTableChanged.
  235.      *
  236.      */
  237.     public void newDataAvailable(TableModelEvent event) {
  238.         fireTableChanged(event);
  239.     }
  240.  
  241.     /**
  242.      *  This method will make sure the new rows have the correct number of columns.
  243.      *  It does so using the setSize method in Vector which truncates Vectors
  244.      *  which are too long, and appends nulls if they are too short.
  245.      *  This method also sends out a tableChanged() notification message
  246.      *  to all the listeners.
  247.      *
  248.      * @parameter event         This TableModelEvent describes where the
  249.      *                          rows were added.  If <b>null</b> it assumes
  250.      *                          all the rows were newly added.
  251.      * @see #getDataVector()
  252.      */
  253.     public void newRowsAdded(TableModelEvent event) {
  254.         int start = event.getFirstRow();
  255.         int end = event.getLastRow();
  256.         if (start < 0)
  257.                 start = 0;
  258.         if (end < 0)
  259.                 end = getRowCount()-1;
  260.  
  261.         // Have to make sure all the new columns have the correct
  262.         // number of columns
  263.         for (int i = start; i < end; i++)
  264.             ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
  265.  
  266.         // Now we send the notification
  267.         fireTableChanged(event);
  268.     }
  269.  
  270.     /**
  271.      *  Equivalent to fireTableChanged().
  272.      *
  273.      */
  274.     public void rowsRemoved(TableModelEvent event) {
  275.         fireTableChanged(event);
  276.     }
  277.  
  278.     /**
  279.      * Replaces the column identifiers in the model.
  280.      *
  281.      * @param   newIdentifiers  Vector of column identifiers.  A null means
  282.      *                          setting the model to zero columns
  283.      * @see #setNumRows()
  284.      */
  285.     public void setColumnIdentifiers(Vector newIdentifiers) {
  286.         if (newIdentifiers != null) {
  287.             columnIdentifiers = newIdentifiers;
  288.         }
  289.         else {
  290.             columnIdentifiers = new Vector();
  291.         }
  292.  
  293.         // Generate notification
  294.         fireTableStructureChanged();
  295.     }
  296.  
  297.     /**
  298.      * Replaces the column identifiers in the model.  If the number of
  299.      * <i>newIdentifiers</i> is greater than the current numColumns,
  300.      * new columns are added to the end of each row in the model.
  301.      * If the number of <i>newIdentifier</i> is less than the current
  302.      * number of columns, all the extra columns at the end of a row are
  303.      * discarded. <p>
  304.      *
  305.      * @param   newIdentifiers  Array of column identifiers.  A null means
  306.      *                          setting the model to zero columns
  307.      * @see #setNumRows()
  308.      */
  309.     public void setColumnIdentifiers(Object[] newIdentifiers) {
  310.         setColumnIdentifiers(convertToVector(newIdentifiers));
  311.     }
  312.  
  313.     /**
  314.      *  Sets the number of rows in the model.  If the new size is greater
  315.      *  than the current size, new rows are added to the end of the model
  316.      *  If the new size is less than the current size, all
  317.      *  rows at index <i>newSize</i> and greater are discarded. <p>
  318.      *
  319.      * @param   newSize   the new number of rows
  320.      * @see #setColumnIdentifiers()
  321.      */
  322.     public void setNumRows(int newSize) {
  323.         if ((newSize < 0) || (newSize == getRowCount()))
  324.             return;
  325.  
  326.         int oldNumRows = getRowCount();
  327.         if (newSize <= getRowCount()) {
  328.             // newSize is smaller than our current size, so we can just
  329.             // let Vector discard the extra rows
  330.             dataVector.setSize(newSize);
  331.  
  332.             // Generate notification
  333.             fireTableRowsDeleted(getRowCount(), oldNumRows-1);
  334.         }
  335.         else {
  336.             int columnCount = getColumnCount();
  337.             // We are adding rows to the model
  338.             while(getRowCount() < newSize) {
  339.                 Vector newRow = new Vector(columnCount);
  340.                 newRow.setSize(columnCount);
  341.                 dataVector.addElement(newRow);
  342.             }
  343.  
  344.             // Generate notification
  345.             fireTableRowsInserted(oldNumRows, getRowCount()-1);
  346.         }
  347.     }
  348.  
  349.     /**
  350.      *  Add a column to the model.  The new column will have the
  351.      *  idenitifier <i>columnName</i>.  This method will send a
  352.      *  tableChanged() notification message to all the listeners.
  353.      *  This method is a cover for <i>addColumn(Object, Vector)</i> which
  354.      *  uses null as the data vector.
  355.      *
  356.      * @param   columnName the identifier of the column being added
  357.      * @exception IllegalArgumentException      if columnName is null
  358.      */
  359.     public void addColumn(Object columnName) {
  360.         addColumn(columnName, (Vector)null);
  361.     }
  362.  
  363.     /**
  364.      *  Add a column to the model.  The new column will have the
  365.      *  idenitifier <i>columnName</i>.  <i>columnData</i> is the
  366.      *  optional Vector of data for the column.  If it is <b>null</b>
  367.      *  the column is filled with <b>null</b> values.  Otherwise,
  368.      *  the new data will be added to model starting with the first
  369.      *  element going to row 0, etc.  This method will send a
  370.      *  tableChanged() notification message to all the listeners.
  371.      *
  372.      * @param   columnName the identifier of the column being added
  373.      * @param   columnData       optional data of the column being added
  374.      * @exception IllegalArgumentException      if columnName is null
  375.      */
  376.     public void addColumn(Object columnName, Vector columnData) {
  377.         if (columnName == null)
  378.             throw new IllegalArgumentException("addColumn() - null parameter");
  379.  
  380.         columnIdentifiers.addElement(columnName);
  381.  
  382.         // Fill in the new column, with nulls or with columnData
  383.         int index = 0;
  384.         Enumeration enumeration = dataVector.elements();
  385.         while (enumeration.hasMoreElements()) {
  386.             Object value;
  387.  
  388.             if ((columnData != null) && (index < columnData.size()))
  389.                 value = columnData.elementAt(index);
  390.             else
  391.                 value = null;
  392.  
  393.             ((Vector)enumeration.nextElement()).addElement(value);
  394.             index++;
  395.         }
  396.  
  397.         // Generate notification
  398.         fireTableStructureChanged();
  399.     }
  400.  
  401.     /**
  402.      *  Adds a column to the model with name <i>columnName</i>.
  403.      *
  404.      * @see #addColumn(Object, Vector)
  405.      */
  406.     public void addColumn(Object columnName, Object[] columnData) {
  407.         addColumn(columnName, convertToVector(columnData));
  408.     }
  409.  
  410.     /**
  411.      *  Add a row to the end of the model.  The new row will contain
  412.      *  <b>null</b> values unless <i>rowData</i> is specified.  Notification
  413.      *  of the row being added will be generated.
  414.      *
  415.      * @param   rowData          optional data of the row being added
  416.      */
  417.     public void addRow(Vector rowData) {
  418.         if (rowData == null) {
  419.             rowData = new Vector(getColumnCount());
  420.         }
  421.         else {
  422.             rowData.setSize(getColumnCount());
  423.         }
  424.  
  425.         dataVector.addElement(rowData);
  426.  
  427.         // Generate notification
  428.         newRowsAdded(new TableModelEvent(this, getRowCount()-1, getRowCount()-1,
  429.                              TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
  430.     }
  431.  
  432.     /**
  433.      *  Add a row to the end of the model.  The new row will contain
  434.      *  <b>null</b> values unless <i>rowData</i> is specified.  Notification
  435.      *  of the row being added will be generated.
  436.      *
  437.      * @param   rowData          optional data of the row being added
  438.      */
  439.     public void addRow(Object[] rowData) {
  440.         addRow(convertToVector(rowData));
  441.     }
  442.  
  443.     /**
  444.      *  Insert a row at <i>row</i> in the model.  The new row will contain
  445.      *  <b>null</b> values unless <i>rowData</i> is specified.  Notification
  446.      *  of the row being added will be generated.
  447.      *
  448.      * @param   row             the row index of the row to be inserted
  449.      * @param   rowData         optional data of the row being added
  450.      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid.
  451.      */
  452.     public void insertRow(int row, Vector rowData) {
  453.         if (rowData == null) {
  454.             rowData = new Vector(getColumnCount());
  455.         }
  456.         else {
  457.             rowData.setSize(getColumnCount());
  458.         }
  459.  
  460.         dataVector.insertElementAt(rowData, row);
  461.  
  462.         // Generate notification
  463.         newRowsAdded(new TableModelEvent(this, row, row,
  464.                              TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
  465.     }
  466.  
  467.     /**
  468.      *  Insert a row at <i>row</i> in the model.  The new row will contain
  469.      *  <b>null</b> values unless <i>rowData</i> is specified.  Notification
  470.      *  of the row being added will be generated.
  471.      *
  472.      * @param   row      the row index of the row to be inserted
  473.      * @param   rowData          optional data of the row being added
  474.      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid.
  475.      */
  476.     public void insertRow(int row, Object[] rowData) {
  477.         insertRow(row, convertToVector(rowData));
  478.     }
  479.  
  480.     /**
  481.      *  Moves one or more rows starting at <i>startIndex</i> to <i>endIndex</i>
  482.      *  in the model to the <i>toIndex</i>.    This method will send a
  483.      *  tableChanged() notification message to all the listeners. <p>
  484.      *
  485.      *  Examples of moves:<p>
  486.      *  1. moveRow(1,3,5);<p>
  487.      *          a|B|C|D|e|f|g|h|i|j|k   - before
  488.      *          a|e|f|B|C|D|g|h|i|j|k   - after
  489.      *  2. moveRow(6,7,1);<p>
  490.      *          a|b|c|d|e|f|G|H|i|j|k   - before
  491.      *          a|G|H|b|c|d|e|f|i|j|k   - after
  492.      *
  493.      * @param   startIndex       the starting row index to be moved
  494.      * @param   endIndex         the ending row index to be moved
  495.      * @param   toIndex          the destination of the rows to be moved
  496.      * @exception  ArrayIndexOutOfBoundsException  if any of the indices are out of
  497.      *                           range.  Or if endIndex is less than startIndex.
  498.      */
  499.     public void moveRow(int startIndex, int endIndex, int toIndex) {
  500.         if ((startIndex < 0) || (startIndex >= getRowCount()))
  501.             throw new ArrayIndexOutOfBoundsException(startIndex);
  502.         if ((endIndex < 0) || (endIndex >= getRowCount()))
  503.             throw new ArrayIndexOutOfBoundsException(endIndex);
  504.         if (startIndex > endIndex)
  505.             throw new ArrayIndexOutOfBoundsException();
  506.  
  507.         if ((startIndex <= toIndex) && (toIndex <= endIndex))
  508.             return;                     // Nothing to move
  509.  
  510.         boolean shift = toIndex < startIndex;
  511.  
  512.         // Do the move by first removing the row, then reinserting it
  513.         for (int i = startIndex; i <= endIndex; i++) {
  514.             Object aRow = dataVector.elementAt(i);
  515.             dataVector.removeElementAt(i);
  516.             dataVector.insertElementAt(aRow, toIndex);
  517.  
  518.             if (shift)
  519.                 toIndex++;
  520.         }
  521.  
  522.         // Generate notification
  523.         fireTableDataChanged();
  524.     }
  525.  
  526.     /**
  527.      *  Remove the row at <i>row</i> from the model.  Notification
  528.      *  of the row being removed will be sent to all the listeners.
  529.      *
  530.      * @param   row      the row index of the row to be removed
  531.      * @exception  ArrayIndexOutOfBoundsException  if the row was invalid.
  532.      */
  533.     public void removeRow(int row) {
  534.         dataVector.removeElementAt(row);
  535.  
  536.         // Generate notification
  537.         fireTableRowsDeleted(row, row);
  538.     }
  539.  
  540. //
  541. // Implementing the TableModel interface
  542. //
  543.  
  544.     /**
  545.      * @return the number of rows in the model.
  546.      */
  547.     public int getRowCount() {
  548.         return dataVector.size();
  549.     }
  550.  
  551.     /**
  552.      * @return the number of columns in the model.
  553.      */
  554.     public int getColumnCount() {
  555.         return columnIdentifiers.size();
  556.     }
  557.  
  558.     /**
  559.      * @return a name for this column using the string value of the
  560.      * appropriate member in <I>columnIdentfiers</I>. If <I>columnIdentfiers</I>
  561.      * is null or does not have and entry for this index return the default
  562.      * name provided by the superclass.
  563.      */
  564.     public String getColumnName(int column) {
  565.         if (columnIdentifiers == null || columnIdentifiers.size() <= column) {
  566.             return super.getColumnName(column);
  567.         }
  568.         Object id = columnIdentifiers.elementAt(column);
  569.         if (id == null) {
  570.             return super.getColumnName(column);
  571.         }
  572.         else {
  573.             return id.toString();
  574.         }
  575.     }
  576.  
  577.     /**
  578.      * Returns true if the cell at <I>row</I> and <I>column</I>
  579.      * is editable.  Otherwise, the setValueAt() on the cell will not change
  580.      * the value of that cell.
  581.      *
  582.      * @param   row             the row whose value is to be looked up
  583.      * @param   column          the column whose value is to be looked up
  584.      * @return                  true if the cell is editable.
  585.      * @see #setValueAt()
  586.      */
  587.     public boolean isCellEditable(int row, int column) {
  588.         return true;
  589.     }
  590.  
  591.     /**
  592.      * Returns an attribute value for the cell at <I>row</I>
  593.      * and <I>column</I>.
  594.      *
  595.      * @param   row             the row whose value is to be looked up
  596.      * @param   column          the column whose value is to be looked up
  597.      * @return                  the value Object at the specified cell
  598.      * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
  599.      *               column was given.
  600.      */
  601.     public Object getValueAt(int row, int column) {
  602.         Vector rowVector = (Vector)dataVector.elementAt(row);
  603.         return rowVector.elementAt(column);
  604.     }
  605.  
  606.     /**
  607.      * Sets the object value for the cell at <I>column</I> and
  608.      * <I>row</I>.  <I>aValue</I> is the new value.  This method
  609.      * will generate a tableChanged() notification.
  610.      *
  611.      * @param   aValue          the new value.  This can be null.
  612.      * @param   row             the row whose value is to be changed
  613.      * @param   column          the column whose value is to be changed
  614.      * @exception  ArrayIndexOutOfBoundsException  if an invalid row or
  615.      *               column was given.
  616.      */
  617.     public void setValueAt(Object aValue, int row, int column) {
  618.         Vector rowVector = (Vector)dataVector.elementAt(row);
  619.         rowVector.setElementAt(aValue, column);
  620.  
  621.         // generate notification
  622.         fireTableChanged(new TableModelEvent(this, row, row, column));
  623.     }
  624.  
  625. //
  626. // Protected Methods
  627. //
  628.  
  629.     /** Returns a Vector that contains the same objects as the array */
  630.     protected static Vector convertToVector(Object[] anArray) {
  631.         if (anArray == null)
  632.             return null;
  633.  
  634.         Vector v = new Vector(anArray.length);
  635.         for (int i=0; i < anArray.length; i++) {
  636.             v.addElement(anArray[i]);
  637.         }
  638.         return v;
  639.     }
  640.  
  641.     /** Returns a Vector of Vectors that contains the same objects as the array */
  642.     protected static Vector convertToVector(Object[][] anArray) {
  643.         if (anArray == null)
  644.             return null;
  645.  
  646.         Vector v = new Vector(anArray.length);
  647.         for (int i=0; i < anArray.length; i++) {
  648.             v.addElement(convertToVector(anArray[i]));
  649.         }
  650.         return v;
  651.     }
  652.  
  653. } // End of class DefaultTableModel
  654.